function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return decodeURI(r[2]); return null; //返回参数值
}

$(function () {
    'use strict';

    $(document).on("pageInit",'#av_rank',function(e, id, page){
        var obj = $(page).find('.page-index')
        $.getJSON('//ineedav.cc:9077/artist/rank', function(remoteData){
            $(remoteData.data.rank).forEach(function(item, index, array){
                var html = '<a href="./production?artist='+ encodeURI(item.artist) +'"><div class="card">' +
                                '<div class="card-content">' +
                                    '<div class="card-content-inner" style="text-align:center;"><img src="' + item.avatar + '" />' +
                                    '</div>' +
                                '</div>' +
                                '<div class="card-footer">' + item.artist + '</div>' +
                            '</div></a>';
                console.log(html);
                obj.append(html)
                //console.log(index, item)
            })
        })
        //console.log(obj);
    });
    $(document).on("pageInit",'#production',function(e, id, page){
        var obj = $(page).find('.page-index')
        var artist = getUrlParam('artist');
        $.getJSON('//ineedav.cc:9077/artist/'+ artist +'/production', function(remoteData){
            $(remoteData.data.last_production).forEach(function(item, index, array){
                var html = '<div class="card">' +
                    '<div class="card-header">'+ item[0] +'</div>' +
                    '<div class="card-content">' +
                    '<div class="card-content-inner" style="text-align:center;"><img src="//' + item[2] + '" />' +
                    '</div>' +
                    '</div>' +
                    '<div class="card-footer">' + item[1] + '</div>' +
                    '</div>';
                //console.log(html);
                obj.append(html)
                //console.log(index, item)
            })
        })
        //console.log(obj);
    });
    $.init();
});